package com.kingland.Weidezhan.controller;

import com.kingland.Weidezhan.Service.UserService;
import com.kingland.Weidezhan.model.UserModel;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class UserController {
    private UserService userService;
    public  UserController(UserService userService){
        this.userService=userService;
    }

    @PostMapping("/user")
    public UserModel addUser(@RequestBody UserModel userModel){
//        response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
//        response.setHeader("Access-Control-Allow-Credentials", "true");
//        response.setHeader("P3P", "CP=CAO PSA OUR");
//        if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) {
//            response.addHeader("Access-Control-Allow-Methods", "POST,GET,TRACE,OPTIONS");
//            response.addHeader("Access-Control-Allow-Headers", "Content-Type,Origin,Accept");
//            response.addHeader("Access-Control-Max-Age", "120");
//        }
        this.userService.addUser(userModel);
        return userModel;
    }

}
